import Vue from "vue";
import VueRouter from "vue-router";
import Home from "../views/Home.vue";
import routerView from "../components/routerView/index.vue";
let originalPush = VueRouter.prototype.push;
VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch((err) => err);
};

//  处理路由替换的警告提示问题
let originalReplace = VueRouter.prototype.replace;
VueRouter.prototype.replace = function push(location) {
  return originalReplace.call(this, location).catch((err) => err);
};
Vue.use(VueRouter);

const routes = [
  {
    path: "/",
    name: "Home",
    component: Home,
    redirect: "index",
    children: [
      {
        path: "/index",
        component: () =>
          import(/* webpackChunkName: "index" */ "../views/index/index.vue"),
        meta: {
          title: "首页",
        },
      },
      {
        path: "/people",
        component: () =>
          import(/* webpackChunkName: "people" */ "../views/people/index.vue"),
        meta: {
          title: "我的",
        },
      },
      {
        path: "/shop",
        component: () =>
          import(/* webpackChunkName: "talk" */ "../views/shop/index.vue"),
        meta: {
          title: "购物车",
        },
      },
      {
        path: "/talk",
        component: () =>
          import(/* webpackChunkName: "shop" */ "../views/talk/index.vue"),
        meta: {
          title: "评论",
        },
      },
    ],
  },
  {
    path: "/detail",
    name: "Detail",
    redirect: "/index/detail",
    component: routerView,
    children: [
      {
        path: "/index/detail",
        component: () =>
          import(
            /* webpackChunkName: "indexDetail" */ "../views/index/detail/index.vue"
          ),
        meta: {
          title: "商品详情",
        },
      },
    ],
  },
  {
    path: "/about",
    name: "About",
    // route level code-splitting
    // this generates a separate chunk (about.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    component: () =>
      import(/* webpackChunkName: "about" */ "../views/About.vue"),
  },
];

const router = new VueRouter({
  routes,
});

export default router;
